package com.bookmanger.server.mapper;

import com.bookmanger.pojo.Entity.ReaderEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ReaderTypeMapper {
    @Select("SELECT rt.max_books FROM reader_type rt JOIN reader r ON r.type_id = rt.id WHERE r.id = #{readerId}")
    Integer getMaxBooksByReaderId(Integer readerId);
    
    @Select("SELECT bl.borrow_days FROM borrow_limit bl JOIN reader r ON r.type_id = bl.reader_type_id WHERE r.id = #{readerId} LIMIT 1")
    Integer getBorrowDaysByReaderId(Integer readerId);

    @Select("SELECT bl.borrow_days FROM borrow_limit bl JOIN reader r ON r.type_id = bl.reader_type_id WHERE r.id = #{readerId} AND bl.book_type_id = #{typeId} LIMIT 1")
    Integer getBorrowDaysByReaderIdAndBookTypeId(Integer readerId, Integer typeId);
}